#include "myQThread.h"

void myQThread::run(){
    emit setPBtnEnableSignal(false);
    int len = name.length();
    if(len == 0)
       {
         emit setPBtnEnableSignal(true);
        return;
    }
    m_stop = false;

    int prevRandInt = 0;
    int randInt = 0;
    while (!m_stop) {
        do{
             randInt = QRandomGenerator::global()->bounded(len);
        }
        while(randInt == prevRandInt);

        QThread::usleep(500);
        QString text = name.at(randInt);
//        QString surname = text.mid(0,1);
//        for(int i = 0;i<text.length()-1;i++)
//        {
//            surname += "*";
//        }
        emit updateLabelSignal(text);
        prevRandInt = randInt;
    }
    emit setPBtnEnableSignal(true);
}

void myQThread::stop()
{
//    this->terminate();
//    this->wait();
    m_stop = true;
    emit setPBtnEnableSignal(true);
}
